<?php
namespace Admin\Controller;
use Lib\Api\TradeDetailApi;
use Think\Controller;
use Think\Model;
class TradeDetailController extends Controller {
    private $modelName = 'TradeDetail';

    public function index() {
        $this->display();
    }

    public function toRechargeOrWithdrawals() {
        $page_size = $_POST['page_size'];
        $page_num = $_POST['page_num'];
        $user_id = $_POST['user_id'];
        $type = $_POST['type'];
        $data_cycle = $_POST['data_cycle'];

        if (null != $data_cycle) {
            $search_date = explode('/', $data_cycle);
            $begin_date = $search_date[0];
            $end_date = $search_date[1];
            $map['DATE_FORMAT(a.datetime, "%Y-%m-%d")'] = array(array('egt', $begin_date), array('elt',$end_date));
        }


        $map['a.type'] = $type;
        $map['a.source'] = 2;
        $map['a.user_id'] = $user_id;
        $field = 'a.out_trade_no, a.datetime, a.fee_money, a.type as pay_type, d.play_name, d.norms, d.mun, d.type, d.real_price, if(a.type=3,0,ifnull(d.gain_price+a.fee_money, 0)) as gain_price ';
        $list = TradeDetailApi::getList($map, $page_num, $page_size, $field, $order='');
        $total = TradeDetailApi::getTotalByOrderToUser($map);

        $list = pageHelper($page_size, $page_num, $list, $total);
        $rel['data'] = $list;
        $this->ajaxReturn($rel);
    }
}